#include "BasicInformation.h"

#include <iomanip>

std::string BasicInformation::ToString() const {
    std::ostringstream oss;
    oss << "name=" << mLabel << " uniqueId= " << mUniqueId << " endpoint=" << mEndpoint;
    oss << " parentId=" << mParentId << " deviceType=0x" << std::hex << std::setw(4) << std::setfill('0') << mDeviceType;
    return oss.str();
}

BasicInformation* BasicInformation::Create(const Json::Value& root) {
    if (root.type() != Json::objectValue) {
        return nullptr;
    }
    const auto node = new BasicInformation();
    node->mEndpoint = static_cast<EndpointId>(root["endpoint"].asInt());
    if (!root["parentId"].empty()) {
        node->mParentId = static_cast<EndpointId>(root["parentId"].asInt());
    }
    if (!root["extra"].empty()) {
        node->mExtra = root["extra"];
    }

    node->mDeviceType = static_cast<DeviceTypeId>(root["deviceType"].asInt());
    node->mLabel = root["label"].asString();;
    node->mVendorName = root["vendorName"].asString();
    node->mProductName = root["productName"].asString();
    node->mManufacturingDate = root["manufacturingDate"].asString();
    node->mSerialNumber = root["serialNumber"].asString();
    node->mUniqueId = root["uniqueId"].asString();
    return node;
}
